package com.heatup.apt.api.filter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import com.heatup.apt.model.api.ApiResultModel;
 
public class HandlerMethodArgumentResolverCustomer implements HandlerMethodArgumentResolver {

	public static final String SESSION_KEY_USERID = "USER_ID";
	private static Logger log=LoggerFactory.getLogger(HandlerMethodArgumentResolverCustomer.class);

	@Override
	public boolean supportsParameter(MethodParameter parameter) {
		return parameter.hasParameterAnnotation(ModelResApi.class);  
	}

	@Override
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
		ApiResultModel<Object> apiResultModel = new ApiResultModel<Object>();
		HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
//		HttpServletResponse response = (HttpServletResponse) webRequest.getNativeResponse();
        HttpSession session = request.getSession();
        
        if(session.getAttribute(SESSION_KEY_USERID) != null){
//        	apiResultModel.setData(new Object());
        	apiResultModel.setErrorCode(ApiResultModel.RET_SUCCESS);
        	apiResultModel.setErrorCode(ApiResultModel.RET_ERROR);
        	apiResultModel.setMsg("");
        	apiResultModel.setLogined(true);
        } 
		return apiResultModel;
	}
	
  
 
}
